package cn.tedu.management.community.controller;


import cn.tedu.management.common.response.JsonResult;
import cn.tedu.management.community.pojo.dto.CommunityParam;
import cn.tedu.management.community.pojo.dto.CommunityQuery;
import cn.tedu.management.community.pojo.vo.CommunityVO;
import cn.tedu.management.community.service.CommunityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "社区模块")
@RestController
@Slf4j
@Validated
@RequestMapping("/v1/community/")
public class CommunityController {
    @Autowired
    private CommunityService communityService;

    @ApiOperation("社区添加")
    @PostMapping("add")
    public JsonResult add(CommunityParam communityParam){
        communityService.addCommunity(communityParam);
        return JsonResult.success();
    }

    @ApiOperation("社区编辑")
    @PostMapping("update")
    public JsonResult update(CommunityParam communityParam){
        communityService.update(communityParam);
        return JsonResult.success();
    }

    @ApiOperation("社区查询")
    @GetMapping("select")
    public JsonResult select(CommunityQuery communityQuery){
        List<CommunityVO> list = communityService.select(communityQuery);
        return JsonResult.success(list);
    }

    @ApiOperation("根据社区id查询社区信息")
    @GetMapping("selectById")
    public JsonResult selectById(Long id){
        CommunityVO communityVO = communityService.selectById(id);
        return JsonResult.success(communityVO);
    }

    @ApiOperation("社区删除")
    @PostMapping("delete")
    public JsonResult delete(Long id){
        communityService.delete(id);
        return JsonResult.success();
    }
}
